const Data=require('yg-Data');
const Main=require('yg-Main');
cc.Class({
    extends: cc.Component,

    properties: {
        mapNode:cc.Node,
        mapContainer:cc.TiledMap,
        memberNode:cc.Node
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        // let GameServerManager=wx.getGameServerManager();
        // GameServerManager.getRoomInfo({
        //     success:(res2)=>{
        //          Data.room.roomInfo=res2.data.roomInfo;
                 this.loadRoomInfo();
        //     }
        // });
        
    },
    //加载房间信息
    loadRoomInfo(){
        let roomExtInfo=JSON.parse(Data.room.roomInfo.roomExtInfo);
        let mapData=Data.maps.find(item=>{return item.id===roomExtInfo.map;});
        //加载地图
        cc.resources.load(mapData.url, (err, map) => {
            this.mapContainer.tmxAsset=null;
            this.mapContainer.tmxAsset=map;
            let mapSize=this.mapContainer.getMapSize();
            let scale=500/(mapSize.width*60);
            this.mapNode.scaleX=scale;
            this.mapNode.scaleY=scale;
        });
        //加载已经在房间内成员的头像
        Data.room.roomInfo.memberList.forEach(item=>{
            let memberExtInfo=JSON.parse(item.memberExtInfo);
            cc.resources.load(`roles/${memberExtInfo.role}/index`, cc.Prefab, (err, prefab) => {
                let user=cc.instantiate(prefab);
                user.x=300;
                user.y=-40;
                this.memberNode.addChild(user);
            });
            cc.resources.load(`lobby/头像昵称`, cc.Prefab, (err, prefab) => {
                let node=cc.instantiate(prefab);
                node.scaleX=0.8;
                node.scaleY=0.8;
                this.memberNode.addChild(node);
                let nodeJs=node.getComponent(require('lobby-userMessage'));
                console.log(nodeJs);
                nodeJs.nickName=item.nickname;
                nodeJs.avatarUrl=item.headimg;
            });
        })
    }

    // update (dt) {},
});
